package com.ruoyi.rocky.service.impl;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.rocky.domain.PcAddTrackingNumber;
import com.ruoyi.rocky.mapper.PcOrderMapper;
import com.ruoyi.rocky.domain.PcOrder;
import com.ruoyi.rocky.domain.PcOrderMaster;
import com.ruoyi.rocky.domain.PcOrderQuery;
import com.ruoyi.rocky.enums.OrderStatus;
import com.ruoyi.rocky.service.PcOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PcOrderServiceImpl implements PcOrderService {

    @Autowired
    private PcOrderMapper pcOrderMapper;

    /**
     * 查询订单
     *
     * @param orderId 订单主键
     * @return 订单
     */
    @Override
    public PcOrder selectPcOrderByOrderId(Long orderId) {
        return pcOrderMapper.selectPcOrderByOrderId(orderId);
    }

    /**
     * 查询订单列表
     *
     * @return 订单
     */
    @Override
    public List<PcOrder> selectPcOrderList() {
        return pcOrderMapper.selectPcOrderList();
    }

    /**
     * 修改订单状态
     *
     * @param pcOrderMaster
     * @return
     */
    @Override
    public R updatePcOrderStatus(PcOrderMaster pcOrderMaster) {
        PcOrderMaster build = PcOrderMaster.builder().status(OrderStatus.UNPAID.getCode()).orderId(pcOrderMaster.getOrderId()).build();
        pcOrderMaster.setStatus(build.getStatus());
        return pcOrderMapper.updatePcOrderStatus(pcOrderMaster) > 0 ? R.ok("修改状态成功") : R.fail("操作失败");
    }

    /**
     * 根据订单状态或门店，车辆查询订单
     * @param orderQuery
     * @return
     */
    @Override
    public List<PcOrder> selectPcOrder(PcOrderQuery orderQuery) {
        return pcOrderMapper.selectPcOrder(orderQuery);
    }

    /**
     * 添加运单号
     * @param pcAddTrackingNumber
     * @return
     */
    @Override
    public R addTrackingNumber(PcAddTrackingNumber pcAddTrackingNumber) {
        return pcOrderMapper.addTrackingNumber(pcAddTrackingNumber)>0?R.ok("添加成功"):R.fail("操作失败");
    }
}
